package com.ntu.rent.web.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
 * 
 * 公司名称:上海天缘迪科<br/>
 * 工程名称:Rent<br/>
 * 包名:com.ntu.rent.web.filters<br/>
 * 文件名:CharactorSetFilter.java<br/>
 * 功能描述:
 * 实现编码格式设置的过滤器
 *<br/>
 * 创建时间:2014-2-19 下午01:37:07<br/>
 * @author zeegates
 *
 */
public class CharactorSetFilter implements Filter {

	private String charactor;
	
	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		req.setCharacterEncoding(charactor);
		chain.doFilter(req, resp);
		resp.setCharacterEncoding(charactor);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		/*从配置文件中读取编码格式*/
		charactor = config.getInitParameter("charset");

	}

}
